<template>
  <div class="app-container">
    <div v-show="!show.detailShow">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="项目名称" prop="fProjectname">
          <el-select v-model="queryParams.fProjectname" placeholder="请选择项目名称" clearable>
            <el-option
              v-for="dict in projectNames"
              :key="dict"
              :label="dict"
              :value="dict"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="任务状态" prop="fStatusname">
          <el-select v-model="queryParams.fStatusname" placeholder="请选择任务状态" clearable>
            <el-option
              v-for="dict in taskStatus"
              :key="dict"
              :label="dict"
              :value="dict"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="调查时间" prop="fSurveytime">
          <el-date-picker clearable
            v-model="queryParams.fSurveytime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择调查时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核时间" prop="fReviewtime">
          <el-date-picker clearable
            v-model="queryParams.fReviewtime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['system:survey:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleShenhe"
            v-hasPermi="['system:survey:edit']"
          >审核</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system:survey:remove']"
          >删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleStatis"
          >统计</el-button>
<!--          <el-button-->
<!--            type="warning"-->
<!--            plain-->
<!--            icon="el-icon-download"-->
<!--            size="mini"-->
<!--            @click="handleExport"-->
<!--          >导出</el-button>-->
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="surveyList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="调查id" align="center" prop="fSurveyid" />
        <el-table-column label="项目名称" align="center" prop="fProjectname" />
        <el-table-column label="图层名称" align="center" prop="fLayername" />
<!--        <el-table-column label="图层id" align="center" prop="fLayerid" />-->
        <el-table-column label="用户id" align="center" prop="fWyUserid" />
        <el-table-column label="用户id" align="center" prop="fNyUserid" />
        <el-table-column label="行政区代码" align="center" prop="fXzqdm" />
        <el-table-column label="状态id" align="center" prop="fStatusid" />
        <el-table-column label="要素唯一标识" align="center" prop="fFeatureid" />
  <!--      <el-table-column label="调查多媒体信息" align="center" prop="fSurveymedia" />-->
  <!--      <el-table-column label="调查属性信息" align="center" prop="fSurveyprop" />-->
<!--        <el-table-column label="核查描述" align="center" prop="fSurveydesc" />-->
<!--        <el-table-column label="审核描述" align="center" prop="fReviewdesc" />-->
        <el-table-column label="调查时间" align="center" prop="fSurveytime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.fSurveytime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="审核时间" align="center" prop="fReviewtime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.fReviewtime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="200dp">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleDetails(scope.row)"
            >详情
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleShenhe(scope.row)"
              v-hasPermi="['system:survey:edit']"
            >审核</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:survey:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <taskDetail v-if="show.detailShow" ref="detail" :show="show"></taskDetail>
    <!-- 添加或修改调查列对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="图层id" prop="fLayerid">
          <el-input v-model="form.fLayerid" placeholder="请输入图层id" />
        </el-form-item>
        <el-form-item label="用户id" prop="fWyUserid">
          <el-input v-model="form.fWyUserid" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="用户id" prop="fNyUserid">
          <el-input v-model="form.fNyUserid" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="行政区代码" prop="fXzqdm">
          <el-input v-model="form.fXzqdm" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="状态id" prop="fStatusid">
          <el-input v-model="form.fStatusid" placeholder="请输入状态id" />
        </el-form-item>
        <el-form-item label="要素唯一标识" prop="fFeatureid">
          <el-input v-model="form.fFeatureid" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="调查多媒体信息" prop="fSurveymedia">
          <el-input v-model="form.fSurveymedia" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="调查属性信息" prop="fSurveyprop">
          <el-input v-model="form.fSurveyprop" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="核查描述" prop="fSurveydesc">
          <el-input v-model="form.fSurveydesc" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="审核描述" prop="fReviewdesc">
          <el-input v-model="form.fReviewdesc" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="调查时间" prop="fSurveytime">
          <el-date-picker clearable
            v-model="form.fSurveytime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择调查时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核时间" prop="fReviewtime">
          <el-date-picker clearable
            v-model="form.fReviewtime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择审核时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {statisSurvey, listSurveyStatus,listSurveyProjects,listSurvey, getSurvey, delSurvey, addSurvey, updateSurvey } from "@/api/survey/survey";
import taskDetail from '@/views/survey/task/taskDetail'

export default {
  name: "Survey",
  components: {taskDetail},
    data() {
    return {
      // 遮罩层
      loading: true,
      projectNames:[],
      taskStatus:[],
      show:{
        detailShow:false,
      },
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 调查列表格数据
      surveyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fLayerid: null,
        fProjectname:null,
        fWyUserid: null,
        fNyUserid: null,
        fXzqdm: null,
        fStatusid: null,
        fStatusname:null,
        fFeatureid: null,
        fSurveymedia: null,
        fSurveyprop: null,
        fSurveydesc: null,
        fReviewdesc: null,
        fSurveytime: null,
        fReviewtime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fFeatureid: [
          { required: true, message: "要素唯一标识不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getProjectList();
  },
  methods: {
    /** 查询调查列列表 */
    getProjectList() {
      let that = this;
      listSurveyProjects().then(response => {
        let projects = response.rows;
        that.projectNames = [];
        for (let i in projects) {
          if(that.projectNames.indexOf(projects[i].f_projectname)==-1){
            that.projectNames.push(projects[i].f_projectname);
          }
        }
      });
      listSurveyStatus().then(response => {
        let status = response.rows;
        that.taskStatus = [];
        for (let i in status) {
          if(that.taskStatus.indexOf(status[i].f_statusname)==-1){
            that.taskStatus.push(status[i].f_statusname);
          }
        }
      });
    },
    getList() {
      let that=this;
      that.loading = true;
      listSurvey(that.queryParams).then(response => {
        that.surveyList = response.rows;
        that.total = response.total;
        that.loading = false;
      });
    },
    handleStatis(){
     statisSurvey().then(response => {
      let stamessage= response.data[0];
      let outmessage="";

      for(let i in stamessage){
        outmessage+=i+"  ： "+stamessage[i]+"<br/><br/>";
      }
       this.$message({
           dangerouslyUseHTMLString: true,
           message: outmessage,
         duration: 5000,// 自动关闭设置时间
         type: 'success' })
     });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fSurveyid: null,
        fLayerid: null,
        fWyUserid: null,
        fNyUserid: null,
        fXzqdm: null,
        fStatusid: null,
        fFeatureid: null,
        fSurveymedia: null,
        fSurveyprop: null,
        fSurveydesc: null,
        fReviewdesc: null,
        fSurveytime: null,
        fReviewtime: null
      };
    //  this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.fSurveyid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加调查列";
    },
    //查看项目详情
    handleDetails(row) {
      this.show.detailShow=true;
      this.currentPro = row
      this.detailDialogOpen = true
      this.dialogTitle=row.xmmc;
      this.$nextTick(() => {
          this.$refs.detail.getCurrentProDetails(this.currentPro)
        }
      )
    },
    /** 修改按钮操作 ，现在没有用*/
    handleShenhe(row) {
      let that=this;
      //2022年11月24日 LQ 审核，本身是修改，现在没啥修改的，改为审核为了验收
      this.$confirm('是否通过审核？ ！', '警告', {
        confirmButtonText: '通过',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
      //  that.reset();
        let ssform={
          fStatusid:4,
          fSurveyid:row.fSurveyid
        };
        updateSurvey(ssform).then(response => {
          that.$modal.msgSuccess("修改成功");
          that.open = false;
          that.getList();
        });
       // that.showAdd.showcp = false
       // that.showAdd.showcp = false
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fSurveyid != null) {
            updateSurvey(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSurvey(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const fSurveyids = row.fSurveyid || this.ids;
      this.$modal.confirm('是否确认删除调查列编号为"' + fSurveyids + '"的数据项？').then(function() {
        return delSurvey(fSurveyids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('survey/export', {
        ...this.queryParams
      }, `survey_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>

</style>
